<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sms extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('sms/sms_model','scm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('sms/themescript/moment.js')),
			script_tag(site_url('sms/themescript/app/sms_contact.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'sms';
		$this->header['pagetitle'] = 'Contact SMS';
		$this->view('sms/sms_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->scm->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		
		if (empty($post['sms_id'])) {
			$post['sms_created_date'] = date('Y-m-d H:i:s');
			unset($post['sms_id']);
			$this->scm->add($post);
		} else {
			$post['sms_modified_date'] = date('Y-m-d H:i:s');
			$this->scm->edit($post, array(
				'sms_id' => $post['sms_id']
			));
		}

		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->scm->delete(array('sms_id' => $post['sms_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

	public function import_contact()
	{
		$data= array();
		$fp = fopen($_FILES['userfile']['tmp_name'], 'r') or die("can't open file");
		while ($csv_line = fgetcsv($fp, 1024)) {
			for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
				$insert_csv = array();
				$insert_csv['sms_fullname'] = $csv_line[0];
				$insert_csv['sms_no'] = $csv_line[1];
				$insert_csv['sms_provider'] = $csv_line[2];
			}

			$data = array(
				'sms_fullname' => $insert_csv['sms_fullname'],
				'sms_no' => $insert_csv['sms_no'],
				'sms_provider' => $insert_csv['sms_provider']
			);
			
			if($data['sms_provider']!='Provider'){
				$this->db-> insert('sms', $data);
			}
		}

		fclose($fp) or die("can't close file");
		
		return TRUE;
	}
}

/* End of file sms_contact.php */
/* Location: .//D/OemahCode/hann/module_admin/sms/controllers/sms_contact.php */